home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / includes / js / joomla.javascript.js < prev    next >
Text File  |  2008-07-06  |  15KB  |  593 lines

  1. // <?php !! This fools phpdocumentor into parsing this file
  2. /**
  3. * @version        $Id: joomla.javascript.js 10389 2008-06-03 11:27:38Z pasamio $
  4. * @package        Joomla
  5. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license        GNU/GPL
  7. * Joomla! is Free Software
  8. */
  9.  
  10. /**
  11.  * Overlib Styling Declarations to allow CSS class override of styles
  12.  *
  13.  */
  14. var ol_fgclass='ol-foreground';
  15. var ol_bgclass='ol-background';
  16. var ol_textfontclass='ol-textfont';
  17. var ol_captionfontclass='ol-captionfont';
  18. var ol_closefontclass='ol-closefont';
  19.  
  20. // general utility for browsing a named array or object
  21. function xshow(o) {
  22.     s = '';
  23.     for(e in o) {s += e+'='+o[e]+'\n';}
  24.     alert( s );
  25. }
  26.  
  27. /**
  28. * Writes a dynamically generated list
  29. * @param string The parameters to insert into the <select> tag
  30. * @param array A javascript array of list options in the form [key,value,text]
  31. * @param string The key to display for the initial state of the list
  32. * @param string The original key that was selected
  33. * @param string The original item value that was selected
  34. */
  35. function writeDynaList( selectParams, source, key, orig_key, orig_val ) {
  36.     var html = '\n    <select ' + selectParams + '>';
  37.     var i = 0;
  38.     for (x in source) {
  39.         if (source[x][0] == key) {
  40.             var selected = '';
  41.             if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
  42.                 selected = 'selected="selected"';
  43.             }
  44.             html += '\n        <option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
  45.         }
  46.         i++;
  47.     }
  48.     html += '\n    </select>';
  49.  
  50.     document.writeln( html );
  51. }
  52.  
  53. /**
  54. * Changes a dynamically generated list
  55. * @param string The name of the list to change
  56. * @param array A javascript array of list options in the form [key,value,text]
  57. * @param string The key to display
  58. * @param string The original key that was selected
  59. * @param string The original item value that was selected
  60. */
  61. function changeDynaList( listname, source, key, orig_key, orig_val ) {
  62.     var list = eval( 'document.adminForm.' + listname );
  63.  
  64.     // empty the list
  65.     for (i in list.options.length) {
  66.         list.options[i] = null;
  67.     }
  68.     i = 0;
  69.     for (x in source) {
  70.         if (source[x][0] == key) {
  71.             opt = new Option();
  72.             opt.value = source[x][1];
  73.             opt.text = source[x][2];
  74.  
  75.             if ((orig_key == key && orig_val == opt.value) || i == 0) {
  76.                 opt.selected = true;
  77.             }
  78.             list.options[i++] = opt;
  79.         }
  80.     }
  81.     list.length = i;
  82. }
  83.  
  84. /**
  85. * Adds a select item(s) from one list to another
  86. */
  87. function addSelectedToList( frmName, srcListName, tgtListName ) {
  88.     var form = eval( 'document.' + frmName );
  89.     var srcList = eval( 'form.' + srcListName );
  90.     var tgtList = eval( 'form.' + tgtListName );
  91.  
  92.     var srcLen = srcList.length;
  93.     var tgtLen = tgtList.length;
  94.     var tgt = "x";
  95.  
  96.     //build array of target items
  97.     for (var i=tgtLen-1; i > -1; i--) {
  98.         tgt += "," + tgtList.options[i].value + ","
  99.     }
  100.  
  101.     //Pull selected resources and add them to list
  102.     //for (var i=srcLen-1; i > -1; i--) {
  103.     for (var i=0; i < srcLen; i++) {
  104.         if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
  105.             opt = new Option( srcList.options[i].text, srcList.options[i].value );
  106.             tgtList.options[tgtList.length] = opt;
  107.         }
  108.     }
  109. }
  110.  
  111. function delSelectedFromList( frmName, srcListName ) {
  112.     var form = eval( 'document.' + frmName );
  113.     var srcList = eval( 'form.' + srcListName );
  114.  
  115.     var srcLen = srcList.length;
  116.  
  117.     for (var i=srcLen-1; i > -1; i--) {
  118.         if (srcList.options[i].selected) {
  119.             srcList.options[i] = null;
  120.         }
  121.     }
  122. }
  123.  
  124. function moveInList( frmName, srcListName, index, to) {
  125.     var form = eval( 'document.' + frmName );
  126.     var srcList = eval( 'form.' + srcListName );
  127.     var total = srcList.options.length-1;
  128.  
  129.     if (index == -1) {
  130.         return false;
  131.     }
  132.     if (to == +1 && index == total) {
  133.         return false;
  134.     }
  135.     if (to == -1 && index == 0) {
  136.         return false;
  137.     }
  138.  
  139.     var items = new Array;
  140.     var values = new Array;
  141.  
  142.     for (i=total; i >= 0; i--) {
  143.         items[i] = srcList.options[i].text;
  144.         values[i] = srcList.options[i].value;
  145.     }
  146.     for (i = total; i >= 0; i--) {
  147.         if (index == i) {
  148.             srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
  149.             srcList.options[i] = new Option(items[i+to], values[i+to]);
  150.             i--;
  151.         } else {
  152.             srcList.options[i] = new Option(items[i], values[i]);
  153.        }
  154.     }
  155.     srcList.focus();
  156.     return true;
  157. }
  158.  
  159. function getSelectedOption( frmName, srcListName ) {
  160.     var form = eval( 'document.' + frmName );
  161.     var srcList = eval( 'form.' + srcListName );
  162.  
  163.     i = srcList.selectedIndex;
  164.     if (i != null && i > -1) {
  165.         return srcList.options[i];
  166.     } else {
  167.         return null;
  168.     }
  169. }
  170.  
  171. function setSelectedValue( frmName, srcListName, value ) {
  172.     var form = eval( 'document.' + frmName );
  173.     var srcList = eval( 'form.' + srcListName );
  174.  
  175.     var srcLen = srcList.length;
  176.  
  177.     for (var i=0; i < srcLen; i++) {
  178.         srcList.options[i].selected = false;
  179.         if (srcList.options[i].value == value) {
  180.             srcList.options[i].selected = true;
  181.         }
  182.     }
  183. }
  184.  
  185. function getSelectedRadio( frmName, srcGroupName ) {
  186.     var form = eval( 'document.' + frmName );
  187.     var srcGroup = eval( 'form.' + srcGroupName );
  188.  
  189.     return radioGetCheckedValue( srcGroup );
  190. }
  191.  
  192. // return the value of the radio button that is checked
  193. // return an empty string if none are checked, or
  194. // there are no radio buttons
  195. function radioGetCheckedValue(radioObj) {
  196.     if (!radioObj) {
  197.         return '';
  198.     }
  199.     var n = radioObj.length;
  200.     if (n == undefined) {
  201.         if (radioObj.checked) {
  202.             return radioObj.value;
  203.         } else {
  204.             return '';
  205.         }
  206.     }
  207.     for (var i = 0; i < n; i++) {
  208.         if(radioObj[i].checked) {
  209.             return radioObj[i].value;
  210.         }
  211.     }
  212.     return '';
  213. }
  214.  
  215. function getSelectedValue( frmName, srcListName ) {
  216.     var form = eval( 'document.' + frmName );
  217.     var srcList = eval( 'form.' + srcListName );
  218.  
  219.     i = srcList.selectedIndex;
  220.     if (i != null && i > -1) {
  221.         return srcList.options[i].value;
  222.     } else {
  223.         return null;
  224.     }
  225. }
  226.  
  227. function getSelectedText( frmName, srcListName ) {
  228.     var form = eval( 'document.' + frmName );
  229.     var srcList = eval( 'form.' + srcListName );
  230.  
  231.     i = srcList.selectedIndex;
  232.     if (i != null && i > -1) {
  233.         return srcList.options[i].text;
  234.     } else {
  235.         return null;
  236.     }
  237. }
  238.  
  239. function chgSelectedValue( frmName, srcListName, value ) {
  240.     var form = eval( 'document.' + frmName );
  241.     var srcList = eval( 'form.' + srcListName );
  242.  
  243.     i = srcList.selectedIndex;
  244.     if (i != null && i > -1) {
  245.         srcList.options[i].value = value;
  246.         return true;
  247.     } else {
  248.         return false;
  249.     }
  250. }
  251.  
  252. /**
  253. * Toggles the check state of a group of boxes
  254. *
  255. * Checkboxes must have an id attribute in the form cb0, cb1...
  256. * @param The number of box to 'check'
  257. * @param An alternative field name
  258. */
  259. function checkAll( n, fldName ) {
  260.   if (!fldName) {
  261.      fldName = 'cb';
  262.   }
  263.     var f = document.adminForm;
  264.     var c = f.toggle.checked;
  265.     var n2 = 0;
  266.     for (i=0; i < n; i++) {
  267.         cb = eval( 'f.' + fldName + '' + i );
  268.         if (cb) {
  269.             cb.checked = c;
  270.             n2++;
  271.         }
  272.     }
  273.     if (c) {
  274.         document.adminForm.boxchecked.value = n2;
  275.     } else {
  276.         document.adminForm.boxchecked.value = 0;
  277.     }
  278. }
  279.  
  280. function listItemTask( id, task ) {
  281.     var f = document.adminForm;
  282.     cb = eval( 'f.' + id );
  283.     if (cb) {
  284.         for (i = 0; true; i++) {
  285.             cbx = eval('f.cb'+i);
  286.             if (!cbx) break;
  287.             cbx.checked = false;
  288.         } // for
  289.         cb.checked = true;
  290.         f.boxchecked.value = 1;
  291.         submitbutton(task);
  292.     }
  293.     return false;
  294. }
  295.  
  296. function hideMainMenu() {
  297.     if (document.adminForm.hidemainmenu) {
  298.         document.adminForm.hidemainmenu.value=1;
  299.     }
  300. }
  301.  
  302. function isChecked(isitchecked){
  303.     if (isitchecked == true){
  304.         document.adminForm.boxchecked.value++;
  305.     }
  306.     else {
  307.         document.adminForm.boxchecked.value--;
  308.     }
  309. }
  310.  
  311. /**
  312. * Default function.  Usually would be overriden by the component
  313. */
  314. function submitbutton(pressbutton) {
  315.     submitform(pressbutton);
  316. }
  317.  
  318. /**
  319. * Submit the admin form
  320. */
  321. function submitform(pressbutton){
  322.     if (pressbutton) {
  323.         document.adminForm.task.value=pressbutton;
  324.     }
  325.     if (typeof document.adminForm.onsubmit == "function") {
  326.         document.adminForm.onsubmit();
  327.     }
  328.     document.adminForm.submit();
  329. }
  330.  
  331. /**
  332. * Submit the control panel admin form
  333. */
  334. function submitcpform(sectionid, id){
  335.     document.adminForm.sectionid.value=sectionid;
  336.     document.adminForm.id.value=id;
  337.     submitbutton("edit");
  338. }
  339.  
  340. /**
  341. * Getting radio button that is selected.
  342. */
  343. function getSelected(allbuttons){
  344.     for (i=0;i<allbuttons.length;i++) {
  345.         if (allbuttons[i].checked) {
  346.             return allbuttons[i].value
  347.         }
  348.     }
  349.     return null;
  350. }
  351.  
  352. // JS Calendar
  353. var calendar = null; // remember the calendar object so that we reuse
  354. // it and avoid creating another
  355.  
  356. // This function gets called when an end-user clicks on some date
  357. function selected(cal, date) {
  358.     cal.sel.value = date; // just update the value of the input field
  359. }
  360.  
  361. // And this gets called when the end-user clicks on the _selected_ date,
  362. // or clicks the "Close" (X) button.  It just hides the calendar without
  363. // destroying it.
  364. function closeHandler(cal) {
  365.     cal.hide();            // hide the calendar
  366.  
  367.     // don't check mousedown on document anymore (used to be able to hide the
  368.     // calendar when someone clicks outside it, see the showCalendar function).
  369.     Calendar.removeEvent(document, "mousedown", checkCalendar);
  370. }
  371.  
  372. // This gets called when the user presses a mouse button anywhere in the
  373. // document, if the calendar is shown.  If the click was outside the open
  374. // calendar this function closes it.
  375. function checkCalendar(ev) {
  376.     var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
  377.     for (; el != null; el = el.parentNode)
  378.     // FIXME: allow end-user to click some link without closing the
  379.     // calendar.  Good to see real-time stylesheet change :)
  380.     if (el == calendar.element || el.tagName == "A") break;
  381.     if (el == null) {
  382.         // calls closeHandler which should hide the calendar.
  383.         calendar.callCloseHandler(); Calendar.stopEvent(ev);
  384.     }
  385. }
  386.  
  387. // This function shows the calendar under the element having the given id.
  388. // It takes care of catching "mousedown" signals on document and hiding the
  389. // calendar if the click was outside.
  390. function showCalendar(id, dateFormat) {
  391.     var el = document.getElementById(id);
  392.     if (calendar != null) {
  393.         // we already have one created, so just update it.
  394.         calendar.hide();        // hide the existing calendar
  395.         calendar.parseDate(el.value); // set it to a new date
  396.     } else {
  397.         // first-time call, create the calendar
  398.         var cal = new Calendar(true, null, selected, closeHandler);
  399.         calendar = cal;        // remember the calendar in the global
  400.         cal.setRange(1900, 2070);    // min/max year allowed
  401.  
  402.         if ( dateFormat )    // optional date format
  403.         {
  404.             cal.setDateFormat(dateFormat);
  405.         }
  406.  
  407.         calendar.create();        // create a popup calendar
  408.         calendar.parseDate(el.value); // set it to a new date
  409.     }
  410.     calendar.sel = el;        // inform it about the input field in use
  411.     calendar.showAtElement(el);    // show the calendar next to the input field
  412.  
  413.     // catch mousedown on the document
  414.     Calendar.addEvent(document, "mousedown", checkCalendar);
  415.     return false;
  416. }
  417.  
  418. /**
  419. * Pops up a new window in the middle of the screen
  420. */
  421. function popupWindow(mypage, myname, w, h, scroll) {
  422.     var winl = (screen.width - w) / 2;
  423.     var wint = (screen.height - h) / 2;
  424.     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  425.     win = window.open(mypage, myname, winprops)
  426.     if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  427. }
  428.  
  429. // LTrim(string) : Returns a copy of a string without leading spaces.
  430. function ltrim(str)
  431. {
  432.    var whitespace = new String(" \t\n\r");
  433.    var s = new String(str);
  434.    if (whitespace.indexOf(s.charAt(0)) != -1) {
  435.       var j=0, i = s.length;
  436.       while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
  437.          j++;
  438.       s = s.substring(j, i);
  439.    }
  440.    return s;
  441. }
  442.  
  443. //RTrim(string) : Returns a copy of a string without trailing spaces.
  444. function rtrim(str)
  445. {
  446.    var whitespace = new String(" \t\n\r");
  447.    var s = new String(str);
  448.    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
  449.       var i = s.length - 1;       // Get length of string
  450.       while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
  451.          i--;
  452.       s = s.substring(0, i+1);
  453.    }
  454.    return s;
  455. }
  456.  
  457. // Trim(string) : Returns a copy of a string without leading or trailing spaces
  458. function trim(str) {
  459.    return rtrim(ltrim(str));
  460. }
  461.  
  462. function mosDHTML(){
  463.     this.ver=navigator.appVersion
  464.     this.agent=navigator.userAgent
  465.     this.dom=document.getElementById?1:0
  466.     this.opera5=this.agent.indexOf("Opera 5")<-1
  467.     this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0;
  468.     this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0;
  469.     this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  470.     this.ie=this.ie4||this.ie5||this.ie6
  471.     this.mac=this.agent.indexOf("Mac")<-1
  472.     this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0;
  473.     this.ns4=(document.layers && !this.dom)?1:0;
  474.     this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
  475.  
  476.     this.activeTab = '';
  477.     this.onTabStyle = 'ontab';
  478.     this.offTabStyle = 'offtab';
  479.  
  480.     this.setElemStyle = function(elem,style) {
  481.         document.getElementById(elem).className = style;
  482.     }
  483.     this.showElem = function(id) {
  484.         if ((elem = document.getElementById(id))) {
  485.             elem.style.visibility = 'visible';
  486.             elem.style.display = 'block';
  487.         }
  488.     }
  489.     this.hideElem = function(id) {
  490.         if ((elem = document.getElementById(id))) {
  491.             elem.style.visibility = 'hidden';
  492.             elem.style.display = 'none';
  493.         }
  494.     }
  495.     this.cycleTab = function(name) {
  496.         if (this.activeTab) {
  497.             this.setElemStyle( this.activeTab, this.offTabStyle );
  498.             page = this.activeTab.replace( 'tab', 'page' );
  499.             this.hideElem(page);
  500.         }
  501.         this.setElemStyle( name, this.onTabStyle );
  502.         this.activeTab = name;
  503.         page = this.activeTab.replace( 'tab', 'page' );
  504.         this.showElem(page);
  505.     }
  506.     return this;
  507. }
  508. var dhtml = new mosDHTML();
  509.  
  510. // needed for Table Column ordering
  511. function tableOrdering( order, dir, task ) {
  512.     var form = document.adminForm;
  513.  
  514.     form.filter_order.value     = order;
  515.     form.filter_order_Dir.value    = dir;
  516.     submitform( task );
  517. }
  518.  
  519. function saveorder( n,  task ) {
  520.     checkAll_button( n, task );
  521. }
  522.  
  523. //needed by saveorder function
  524. function checkAll_button( n, task ) {
  525.  
  526.     if (!task ) {
  527.         task = 'saveorder';
  528.     }
  529.  
  530.     for ( var j = 0; j <= n; j++ ) {
  531.         box = eval( "document.adminForm.cb" + j );
  532.         if ( box ) {
  533.             if ( box.checked == false ) {
  534.                 box.checked = true;
  535.             }
  536.         } else {
  537.             alert("You cannot change the order of items, as an item in the list is `Checked Out`");
  538.             return;
  539.         }
  540.     }
  541.     submitform(task);
  542. }
  543. /**
  544. * @param object A form element
  545. * @param string The name of the element to find
  546. */
  547. function getElementByName( f, name ) {
  548.     if (f.elements) {
  549.         for (i=0, n=f.elements.length; i < n; i++) {
  550.             if (f.elements[i].name == name) {
  551.                 return f.elements[i];
  552.             }
  553.         }
  554.     }
  555.     return null;
  556. }
  557.  
  558. function go2( pressbutton, menu, id ) {
  559.     var form = document.adminForm;
  560.  
  561.     if (form.imagelist && form.images) {
  562.         // assemble the images back into one field
  563.         var temp = new Array;
  564.         for (var i=0, n=form.imagelist.options.length; i < n; i++) {
  565.             temp[i] = form.imagelist.options[i].value;
  566.         }
  567.         form.images.value = temp.join( '\n' );
  568.     }
  569.  
  570.     if (pressbutton == 'go2menu') {
  571.         form.menu.value = menu;
  572.         submitform( pressbutton );
  573.         return;
  574.     }
  575.  
  576.     if (pressbutton == 'go2menuitem') {
  577.         form.menu.value     = menu;
  578.         form.menuid.value     = id;
  579.         submitform( pressbutton );
  580.         return;
  581.     }
  582. }
  583. /**
  584.  * Verifies if the string is in a valid email format
  585.  * @param    string
  586.  * @return    boolean
  587.  */
  588. function isEmail( text )
  589. {
  590.     var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
  591.     var regex = new RegExp( pattern );
  592.     return regex.test( text );
  593. }